package com.atguigu.tingshu.search.receive;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.search.service.SearchService;
import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: jack
 * @date: 2025/9/25 17:07
 */
@Slf4j
@Component
public class SearchReceive {

    @Autowired
    private SearchService searchService;

    @SneakyThrows
    @RabbitListener(bindings = @QueueBinding(exchange = @Exchange(value = MqConst.EXCHANGE_ALBUM),
            value = @Queue(value = MqConst.QUEUE_ALBUM_UPPER),
            key = MqConst.ROUTING_ALBUM_UPPER))
    public void upperAlbum(Long albumId, Message message, Channel channel) {
        log.info("接收到消息：{}", albumId);
        searchService.upperAlbum(albumId);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
